<?php
ob_implicit_flush();
include "../Lib/Include.php";
$Domain=$_GET["S"];
$SiteStr="";
//提取页面内容和搞定打开时间
$Start=microtime(true);
$PageCode=file_get_contents("http://".$Domain);
$fp = fsockopen($Domain, 80, $errno, $errstr, 30);
if(!$fp){
	echo "$errstr ($errno)<br />\n";
}else{
	$out = "GET / HTTP/1.1\r\n" ;
	$out .= "Host: ".$Domain."\r\n" ;
	$out .= "Connection: Close\r\n\r\n" ; 
	fwrite($fp, $out);
	$PageCode="";
	while (!feof($fp)) {
		$PageCode.= fgets($fp, 128);
	}
	fclose($fp); 
}
$Finish=microtime(true);
$GetTime=$Finish-$Start;

$SiteStr=$GetTime;

//判断编码进行转码
if(strpos(strtolower($PageCode),"charset=gb2312")>0){
	$PageCode=mb_convert_encoding($PageCode,"UTF-8","gb2312");
}
//提取网页标题
$Arr=spliti("<title>",$PageCode);
$Arr=spliti("</title>",$Arr[1]);
$PageTitle=$Arr[0];
$SiteStr.="|||".$PageTitle;

//提取网页描述
$Arr=spliti("description\" content=\"",$PageCode);
$Arr=spliti("\"",$Arr[1]);
$PageDescription=$Arr[0];
$SiteStr.="|||".$PageDescription;

//提取网页关键字
$Arr=spliti("keywords\" content=\"",$PageCode);
$Arr=spliti("\"",$Arr[1]);
$PageKeywords=$Arr[0];
$SiteStr.="|||".$PageKeywords;

//提取网页内链与外链
$LinkCount1=0;
$LinkCount2=0;
$Arr=spliti("<a",$PageCode);
for($i=1;$i<count($Arr)-1;$i++){
	$Arr2=spliti("</a>",$Arr[$i]);
	if(strpos($Arr2[0],$Domain)!=""||strpos($Arr2[0],"http://")==""){
		$LinkCount1=$LinkCount1+1;
	}else{
		$LinkCount2=$LinkCount2+1;
	}
}
$SiteStr.="|||"."内链".$LinkCount1."个，外链".$LinkCount2."个";

//提取网页图片
$ImageCount=0;
$ImageAltCount=0;
$Arr=spliti("<img",$PageCode);
$ImageCount=count($Arr)-1;
for($i=1;$i<count($Arr)-1;$i++){
	$Arr2=spliti(">",$Arr[$i]);
	if(strpos($Arr2[0],"alt=")!=""){
		$ImageAltCount=$ImageAltCount+1;
	}
}
$SiteStr.="|||"."共有".$ImageCount."个图片，".$ImageAltCount."个图片有Alt标签";
echo $SiteStr;
?>